package http;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;
import android.widget.Toast;

import java.util.HashMap;

import bean.BaseResponse;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * 抽象类实现Observer（如果是直接返回string，就需要用到这个）
 */
public abstract class StringObserver implements Observer<String> {

    private Context mContext;

    public StringObserver(Context mContext) {
        this.mContext = mContext;
    }


    @Override
    public void onSubscribe(Disposable d) {

    }

    @Override
    public void onNext(String string) {
        HashMap<String, String> str = AnalyticalJSON.getHashMap(string);
        if (str.get("rCode").equals("0")) {
            onSuccess(string);
        } else {
            onFailure(null,str.get("rCode")+"==="+str.get("message"));
        }
    }

    @Override
    public void onError(Throwable e) {
        onFailure(e,  RxExceptionUtil.exceptionHandler(e));
    }

    @Override
    public void onComplete() {

    }

    public abstract void onSuccess(String s);

    public abstract void onFailure(Throwable e, String errorMsg);


}
